home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / MESSAGES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  2.7 KB  |  105 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <MINTBIND.H>
  9. #include <OSBIND.H>
  10. #include <memory.h>
  11. #include "XA_DEFS.H"
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "K_DEFS.H"
  15. #include "EVNT_MUL.H"
  16.  
  17. /*
  18.     Send an AES message to a client application
  19. */
  20. void send_app_message(short dest_id, short mesg, short source_id, short a, short b, short c, short d, short e)
  21. {
  22.     XA_AESMSG_LIST *new_msg,*ml;
  23.     XA_CLIENT *dest_client;
  24.     short *clnt_buf;
  25.     unsigned long retv=XA_OK;
  26.     
  27.     if (dest_id==AESpid)     /* Just a precaution - we don't want to send messages to ourselves..... */
  28.         return;
  29.  
  30.     dest_client=Pid2Client(dest_id);
  31.  
  32.     if (!dest_client)
  33.     {
  34.         DIAGS(("WARNING: Invalid target pid [%d] for send_app_message()\n",dest_id));
  35.         return;
  36.     }
  37.  
  38.     Psemaphore(2,CLIENTS_SEMAPHORE,-1L);
  39.     
  40.     if (dest_client->waiting_for&XAWAIT_MESSAGE)    /* Is the dest client waiting for a message at the moment? */
  41.     {
  42.  
  43.         if (dest_client->waiting_for&XAWAIT_MULTI)    /* If the client is waiting on a multi, the response is  */
  44.         {                                                /* slightly different to the evnt_mesag() response. */
  45.  
  46.             dest_client->waiting_pb->intout[0]=MU_MESAG;
  47.             cancel_evnt_multi(dest_id);
  48.         }else{
  49.         
  50.             dest_client->waiting_pb->intout[0]=1;
  51.             dest_client->waiting_for=0;    /* flag client as not waiting for anything */
  52.         }
  53.  
  54.         clnt_buf=(short*)(dest_client->waiting_pb->addrin[0]);
  55.         
  56.         if (!clnt_buf)
  57.         {
  58.             DIAGS(("WARNING: Invalid target message buffer\n"));
  59.             return;
  60.         }
  61.         
  62.         clnt_buf[0]=mesg;            /* Fill in the clients message buffer */
  63.         clnt_buf[1]=source_id;
  64.         clnt_buf[2]=0;
  65.         clnt_buf[3]=a;
  66.         clnt_buf[4]=b;
  67.         clnt_buf[5]=c;
  68.         clnt_buf[6]=d;
  69.         clnt_buf[7]=e;
  70.  
  71.         Fwrite(dest_client->clnt_pipe_wr, (long)sizeof(unsigned long),&retv);    /* Write success to clients reply pipe to unblock the process */
  72.     }else{    /* Create a new entry in the destination client's pending messages list */
  73.         new_msg=(XA_AESMSG_LIST*)malloc(sizeof(XA_AESMSG_LIST));
  74.         
  75.         if (new_msg)
  76.         {
  77.         
  78.             new_msg->message[0]=mesg;            /* Fill in the new pending list entry with the message */
  79.             new_msg->message[1]=source_id;
  80.             new_msg->message[2]=0;
  81.             new_msg->message[3]=a;
  82.             new_msg->message[4]=b;
  83.             new_msg->message[5]=c;
  84.             new_msg->message[6]=d;
  85.             new_msg->message[7]=e;
  86.             new_msg->next=NULL;
  87.  
  88.             if (dest_client->msg)    /* There are already some pending messages */
  89.             {
  90.  
  91.                 for(ml=dest_client->msg; ml->next; ml=ml->next);
  92.                 ml->next=new_msg;    /* Append the new message to the list */
  93.         
  94.             }else{    /* First entry in the clients pending message list */
  95.             
  96.                 dest_client->msg=new_msg;
  97.         
  98.             }
  99.         }
  100.     }
  101.     
  102.     Psemaphore(3,CLIENTS_SEMAPHORE,0L);
  103.     
  104. }
  105.